package com.example.a2205douyin.fragment;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.a2205douyin.R;
import com.example.a2205douyin.adapter.MyFragAdapter;
import com.example.a2205douyin.baseMVVM.view.BaseViewFragment;
import com.example.a2205douyin.databinding.FragmentHomeBinding;
import com.example.a2205douyin.entity.TabEntity;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseViewFragment<FragmentHomeBinding> {

    List<Fragment> list = new ArrayList<>();
    MyFragAdapter myFragAdapter;
    ArrayList<CustomTabEntity> tabs = new ArrayList<>();

    public HomeFragment() {
        // Required empty public constructor
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        list.add(new TuijianFragment());
        list.add(new ShoppingFragment());
        myFragAdapter = new MyFragAdapter(getActivity(),list);
        binding.vp.setAdapter(myFragAdapter);

        tabs.add(new TabEntity("推荐",0,0));
        tabs.add(new TabEntity("商城",0,0));
        binding.common.setTabData(tabs);

        binding.vp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                binding.common.setCurrentTab(position);
            }
        });
        binding.common.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                binding.vp.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_home;
    }
}